package com.pureland.security;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer;
import org.springframework.stereotype.Component;

/**
 * @projectName: pureland_cloud
 * @className: com.pureland.ucc.config.oauth.ResourceServerConfigurer
 * @description: 资源认证配置类
 * @author: tong.li
 * @createTime: 2020/11/19 16:32
 * @version: v1.0
 * @copyright: 版权所有 李彤 © 2020
 */
@Configuration
@EnableResourceServer
@Component
@Primary
public class ResourceServerConfigurer extends ResourceServerConfigurerAdapter {

    @Autowired
    private ResourceAuthExceptionEntryPoint authenticationEntryPoint;

    @Override
    public void configure(HttpSecurity http) throws Exception {
        http.csrf().disable()
                .authorizeRequests()
                .anyRequest()
                .authenticated();
    }

    @Override
    public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
        resources.authenticationEntryPoint(authenticationEntryPoint);
    }

}
